import ReactECharts from "echarts-for-react";
import {history} from "@@/core/history";
import {useEffect, useState} from "react";
import {Detail04Hold, Detail04Platform} from "@/services/Province/Dashboard";
import {ProvinceAllUrl} from "@/utils/format";
import {Link} from "@umijs/preset-dumi/lib/theme";

const Gmm04_4 = (props) => {
  // echarts Demo 数据
  // const options = {
  //   title: {
  //     text: '学科主持科研项目情况',
  //     // subtext: 'Fake Data',
  //     left: 'center'
  //   },
  //   tooltip: {
  //     trigger: 'axis',
  //   },
  //   // legend: {
  //   //   // top: 'center',
  //   // },
  //   grid: {
  //     left: '5%',
  //     right: '4%',
  //     bottom: '5%',
  //     containLabel: true
  //   },
  //   xAxis: [
  //     {
  //       type: 'category',
  //       data: ['国家重点重大项目', '国家一般项目', '省级重点重大项目']
  //     }
  //   ],
  //   yAxis: [
  //     {
  //       type: 'value'
  //     }
  //   ],
  //   barWidth: 35,
  //   series: [
  //     {
  //       name: '历史存量',
  //       type: 'bar',
  //       stack: 'Ad',
  //       emphasis: {
  //         focus: 'series'
  //       },
  //       data: [4, 7, 12]
  //     },
  //     {
  //       name: '本年度新增',
  //       type: 'bar',
  //       stack: 'Ad',
  //       emphasis: {
  //         focus: 'series'
  //       },
  //       data: [1, 3, 4]
  //     },
  //   ]
  // };

  const urlArr = history.location.pathname.split('/')
  const school = urlArr[urlArr.length - 1]
  const subject = urlArr[urlArr.length - 2]
  const schoolSubject = school + '-' + subject
  const [options, setoptions] = useState({})
  const [reload, setreload] = useState(false)
  useEffect(() => {
    Detail04Hold({subject: schoolSubject}).then(res => {
      if (res.status === 0) {
        setoptions({
          title: {
            text: '学科主持科研项目情况',
            // subtext: 'Fake Data',
            left: 'center'
          },
          tooltip: {
            trigger: 'axis',
          },
          // legend: {
          //   // top: 'center',
          // },
          grid: {
            left: '5%',
            right: '4%',
            bottom: '5%',
            containLabel: true
          },
          xAxis: [
            {
              type: 'category',
              data: res.name
            }
          ],
          yAxis: [
            {
              type: 'value'
            }
          ],
          barWidth: 35,
          series: [
            {
              name: '历史存量',
              type: 'bar',
              stack: 'Ad',
              emphasis: {
                focus: 'series'
              },
              data: res.value
            },
          ]
        })
      }
    })
  }, [reload])

  const url = ProvinceAllUrl(school, subject, '4_2_2_0,4_2_2_1,4_2_2_2,4_2_2_3', '学科主持科研项目情况')

  return <>
    <Link to={url}>详情</Link>
    <ReactECharts style={{width: 500, height: 400}} option={options} />
  </>
}

export default Gmm04_4
